<%--
  Created by IntelliJ IDEA.
  User: ddd
  Date: 2018/4/15
  Time: 15:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>套题查看</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/static/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="/static/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/static/css/style.min.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/css/admin.css">
</head>
<style>
    .admin-so {
        height: 30px;
        line-height: 40px;
        margin-bottom: 10px;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="container-fluid">
        <div class="row" id="row2">
            <input type="hidden" id="taotiid" value="">
            <div class="col-md-8">
                <div class="admin-so"><a href="javascript:void(0);" class="btn btn-info" onclick="winclose()">
                    <i class="fa fa-rotate-left"></i> 返回上一级</a></div>
            </div>
            <div class="col-md-2 col-md-offset-1">
                <button class="btn btn-success" onclick="AddSecondSub()">新增题目</button>
                <button class="btn btn-danger" onclick="Removetimu()">批量移除</button>
            </div>
            <table id="viewtable"></table>
        </div>
    </div>
</div>

<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script src="/static/js/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="/static/js/plugins/bootstrap-table/bootstrap-table-mobile.js"></script>
<script src="/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="/static/js/demo/bootstrap-table-demo.min.js"></script>
<script type="text/javascript">

    var $view = $("#viewtable");
    function biaoge() {
        var tid = $("#taotiid").val();
        var url = "/subjectBySeid?seid=" + tid;
        $view.bootstrapTable({
            url: url,
            method: 'get',
            striped: true,
            cache: false,
            height: 655,
            pagination: true,
            sidePagination: "client",
            queryParams: function (params) { // 请求服务器数据时发送的参数，可以在这里添加额外的查询参数，返回false则终止请求

            },
            pageNumber: 1,
            pageSize: 15,
            pageList: [],
            paginationLoop: false,
            clickToSelect: true,
            uniqueId: "id",
            columns: [{
                checkbox: true
            }, {
                field: 'secondSubId',
                title: '序号'
            }, {
                field: 'id',
                title: '题库ID'
            }, {
                field: 'problem',
                title: '题目'
            }, {
                field: 'type',
                title: '类型',
                formatter: function (value, row) {
                    if (row.type === 0) {
                        return "单选题";
                    } else if (row.type === 1) {
                        return "判断题";
                    } else {
                        return "多选题";
                    }
                }
            }, {
                field: 'sort',
                title: '排序'
            }, {
                title: '操作',
                clickToSelect: false,
                formatter: function (value, row) {
                    return "<a class='btn btn-xs btn-primary' href='javascript:void(0);' onclick=\"ShwoDetail1("+row.id+")\">查看</a>\n" +
                        "<a class='btn btn-xs btn-warning' href='javascript:void(0);' onclick=\"ShwoDetail2("+row.id+")\">查看(藏)</a>\n" +
                        "<a class='btn btn-xs btn-success' onclick=\"SsOrder("+row.id+")\">排序</a>\n" +
                        "<a class='btn btn-xs btn-danger' href='javascript:void(0);' onclick=\"DelSSid("+row.secondSubId+")\">移除</a>"
                }
            }]
        });
    }

    //关闭layer
    function winclose() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    //增加题目
    function AddSecondSub() {
        var tid = $("#taotiid").val();
        layer.open({
            type: 2,
            title: '新增题目信息',
            area: ['500px', '50%'],
            fixed: false, //不固定
            maxmin: true,
            content: "/page/secondtype/secondtype_subject_addsubject.jsp",
            success: function (layero, index) {
                var body = layer.getChildFrame('body', index);
                body.find("input[name='seid']").val(tid);
            }
        });
    }

    //查看题目
    function ShwoDetail1(key) {
        layer.open({
            type: 2,
            title: '查看题目信息',
            area: ['1000px', '90%'],
            fixed: false, //不固定
            maxmin: true,
            content: "/page/secondtype/secondtype_subject_view_1.jsp?key="+key
        });
    }
    //查看题目（藏）
    function ShwoDetail2(key) {
        layer.open({
            type: 2,
            title: '查看题目信息',
            area: ['1000px', '90%'],
            fixed: false, //不固定
            maxmin: true,
            content: "/page/secondtype/secondtype_subject_view_2.jsp?key="+key
        });
    }

    //排序
    function SsOrder(key) {
        var aa = $view.bootstrapTable('getRowByUniqueId', key);
        layer.open({
            type: 2,
            title: '排序',
            area: ['500px', '40%'],
            fixed: false, //不固定
            maxmin: true,
            content: "/page/secondtype/secondtype_subject_orderby.jsp?key="+key,
            success: function (layero, index) {
                var body = layer.getChildFrame('body', index);
                body.find("input[name='sort']").val(aa.sort);
                body.find("input[name='secondSubId']").val(aa.secondSubId);
            }
        });
    }

    //移除题目
    function DelSSid(key) {
        layer.confirm('确定是否从此套题中移除', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                contentType: 'application/json;charset=UTF-8',
                type: 'delete',
                url: "/secondType/relateSub",
                data: JSON.stringify([key]),
                success: function (json) {
                    if (json.status === "success") {
                        layer.msg('操作成功', {icon: 1, time: 1000});
                        $view.bootstrapTable('refresh');
                    } else {
                        layer.msg(json.msg, {icon: 2, time: 1000});
                    }
                },
                error: function () {
                    layer.msg('网络连接失败', {icon: 5, time: 1000});
                }
            });
        }, function () {
            layer.msg('取消操作成功', {icon: 1, time: 1000});
        });
    }

    //多选移除题目
    function Removetimu() {
        var ids = $.map($view.bootstrapTable('getSelections'), function (row) {
            return row.secondSubId;
        });
        if (ids.length === 0) {
            layer.msg('请选择数据')
        } else {
            layer.confirm('确定是否移除选择的题目', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    contentType: 'application/json;charset=UTF-8',
                    type: 'delete',
                    url: "/secondType/relateSub",
                    data: JSON.stringify(ids),
                    dataType: 'json',
                    success: function (json) {
                        if (json.status === "success"){
                            layer.msg('操作成功', {icon: 1, time: 1000});
                            $view.bootstrapTable('refresh');
                        } else {
                            layer.msg(json.status, {icon: 2, time: 1000});
                        }
                    },
                    error: function () {
                        layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
                    }
                });
            }, function () {
                layer.msg('取消操作成功', {icon: 1, time: 1000});
            });
        }
    }
</script>
</body>
</html>
